﻿<%@ Page Title="修改个人信息" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" AutoEventWireup="true" CodeBehind="EditProfile.aspx.cs" Inherits="RegexLib.Web.Views.Member.EditProfile" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<% UserInfo user = (UserInfo)ViewData.Model; %>
<div class="box">
	<div class="bt">修改个人信息</div>
	<div class="bc">
	<form id="EditForm" action="/Member/EditProfileSubmit/" method="post">
		<input type="hidden" name="userId" value="<%= user.UserId %>" />
		<table>
			<tr><td>昵称：</td><td><input type="text" name="userNickname" class="input" value="<%= user.Nickname %>" maxlength="50" /></td></tr>
			<tr><td>密码：</td><td><a href="/Member/ChangePassword/">重置密码</a></td></tr>
		</table>
	</form>
	<button id="SubmitBtn">确定</button>
	<p><span id="MsgSpan"></span></p>
	</div>
</div>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ScriptPlaceHolder" runat="server">
<script type="text/javascript">
var c_EditForm;
var c_SubmitBtn;
var c_MsgSpan;

function GetElements()
{
	c_EditForm = YAHOO.util.Dom.get("EditForm");
	c_SubmitBtn = YAHOO.util.Dom.get("SubmitBtn");
	c_MsgSpan = YAHOO.util.Dom.get("MsgSpan");
}

function SetErrMessage(msg)
{
	c_MsgSpan.className="err";
	c_MsgSpan.innerText = msg;
}

function DoEdit()
{
	c_SubmitBtn.disabled = true;
	
	var callback =
	{
		success: function(o)
		{
			try
			{
				var data = YAHOO.lang.JSON.parse(o.responseText);
				if(data.IsError)
				{
					SetErrMessage(data.Message);
					c_SubmitBtn.disabled = false;
				}
				else
				{
					window.location = data.Message;
				}
			}
			catch(e)
			{
				SetErrMessage("解析响应时出错，请稍后再试。");
				c_SubmitBtn.disabled = false;
			}
		},
		failure: function(o)
		{
			SetErrMessage("未知错误。");
			c_SubmitBtn.disabled = false;
		},
		timeout: 30000
	};
	
	YAHOO.util.Connect.setForm(c_EditForm);
	YAHOO.util.Connect.asyncRequest("POST", "/Member/EditProfileSubmit/", callback, null);
}

function init()
{
	GetElements();
	YAHOO.util.Event.addListener(c_SubmitBtn, "click", DoEdit);
}

YAHOO.util.Event.onDOMReady(init);
</script>
</asp:Content>
